const express = require('express')
let cors = require('cors')
let bodyParser = require('body-parser')
let session = require('express-session')
let app = express()

// 跨域使用
// app.use(cors({
//     origin: 'http://localhost:3006'
// }))

let user = [{ jinhua: 'hong hong' }, { jinhua: 'hong hong' }]

app.get('/api/users', function (req, res) {
    res.json(user)
})

app.get('/api/login', function (req, res) {
    let user = req.body;
    res.json({
        code: 0,
        data: {
            name: 'name er',
            success: '登陆成功！！！'
        }
    })
})

app.get('/api/login', function (req, res) {
    // req.session.user = null;
    res.json({
        code: 0,
        data: {
            success: '退出成功！！！'
        }
    })
})

app.get('/api/user', function (req, res) {
    // let user = req.session.user;
    // if (user) {
        let newData = [
            {
                code: 0,
                data: {
                    success: '获取用户信息成功！！！',
                    user: 'jin hua'
                }
            }
        ]   
        res.json(newData)
    // } else {
    //     res.json({
    //         code: 0,
    //         data: {
    //             error: '用户未登录！！！'
    //         }
    //     })
    // }
})

app.listen(4000, function () {
    console.log(4000)
})
